//
//  PlayViewController.m
//  RONGAO
//
//  Created by wei wang on 2017/3/14.
//  Copyright © 2017年 wei wang. All rights reserved.
//

#import "PlayViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import "videoPlayerView.h"
#import <AVKit/AVKit.h>
@interface PlayViewController ()

@property (strong,nonatomic) AVPlayerViewController *moviePlayer;
@property (strong,nonatomic) AVPlayer *player;
/** <#Description#> **/
@property(nonatomic,strong) AVPlayerItem *item;
@end

@implementation PlayViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setNavigationStyle];

    NSURL *url=[NSURL fileURLWithPath:[self.videoPath stringByAppendingPathComponent:self.videoFileName]];
    AVAsset *asset = [AVAsset assetWithURL:url];
    
    self.item=[AVPlayerItem playerItemWithAsset:asset];
    self.player=[AVPlayer playerWithPlayerItem:self.item];
    self.moviePlayer=[[AVPlayerViewController alloc]init];
    
    self.moviePlayer.player=self.player;
    
    [self.view addSubview:self.moviePlayer.view];
    
    //设置AVPlayerViewController的frame
    self.moviePlayer.view.frame=self.view.frame;
    //设置流媒体视频路径
    [self.player play];
    
}

- (BOOL)prefersStatusBarHidden {
    return NO;
}


- (void)setNavigationStyle{
    [self setNavigationTitle:@"视频播放" titleColor:[UIColor colorWithRed:210/255.0 green:177/255.0 blue:104/255.0 alpha:1]];
    [self setLeftButtonImage:[UIImage imageNamed:@"icon_back_nor"]];
}


-(void)endPlay
{
    [self dismissMoviePlayerViewControllerAnimated];
    
    NSLog(@"播放结束");
}

#pragma mark - dealloc

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
